package com.jueyue.dao.pager.dialect;

import com.jueyue.dao.util.PublicUtil;

/**
 * @author JueYue
 * @date 2014年1月12日
 * @version 1.0
 */
public class DialectFactory {
	private static final String ORACLE = "oracle";
	private static final String MYSQL = "mysql";
	/*
	 * private static final String SQLSERVER = "sqlserver"; private static final
	 * String DB2 = "db2"; private static final String POSTGRES = "postgres";
	 */
	private static SqlDialect dialect;
	private static String dbType = "mysql";

	static {
		dbType = PublicUtil.getProperties("dialectType");
		if (!dbType.equals(ORACLE) && !dbType.equals(MYSQL)) {
			try {
				throw new Exception("填写的数据库类型,暂时不支持");
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	public static SqlDialect getSQLDialect() {
		return dialect != null ? dialect : createSqlDialect();
	}

	private static SqlDialect createSqlDialect() {
		if (dbType.equals(ORACLE)) {
			dialect = new OracleDialect();
		} else if (dbType.equals(MYSQL)) {
			dialect = new MySQLDialect();
		}
		return dialect;
	}
}